//
//  FriendsDynamicVC.m
//  Connections
//
//  Created by beisheng03 on 2017/10/11.
//  Copyright © 2017年 beisheng. All rights reserved.
//

#import "FriendsDynamicVC.h"
#import "FriendDynamiCell.h"
#import "FriendCommentCell.h"
#import "LookMoreCommentCell.h"
#import "SendCommentView.h"

@interface FriendsDynamicVC ()<FriendDynamiCellDelegate>
/** <#note#> */
@property (nonatomic, weak) SendCommentView *sendView;

/**  */
@property (nonatomic, strong) UITextField *sendTextField;

/** q */
@end

@implementation FriendsDynamicVC

- (SendCommentView *)sendView{
    
    if (!_sendView) {
        
        SendCommentView *temp = (SendCommentView *)[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([SendCommentView class]) owner:nil options:nil].firstObject;
        
        _sendTextField = (UITextField *)[temp viewWithTag:99];
        
        _sendView = temp;
        
        [self.view addSubview:temp];
    }
    
    return _sendView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"好友动态";
    
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChange:) name:UIKeyboardWillChangeFrameNotification object:nil];
    
    [self.groupTableView registerNib:[UINib nibWithNibName:NSStringFromClass([FriendDynamiCell class]) bundle:nil] forCellReuseIdentifier:[FriendDynamiCell identifierStr]];
    
    
    
  [self.groupTableView registerNib:[UINib nibWithNibName:NSStringFromClass([FriendCommentCell class]) bundle:nil] forCellReuseIdentifier:[FriendCommentCell identifierStr]];
    
   [self.groupTableView registerNib:[UINib nibWithNibName:NSStringFromClass([LookMoreCommentCell class]) bundle:nil] forCellReuseIdentifier:[LookMoreCommentCell identifierStr]];
    
    self.groupTableView.rowHeight = UITableViewAutomaticDimension;
    
    self.groupTableView.estimatedRowHeight = 100;
    
    self.groupTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    self.sendView.frame = CGRectMake(0, KScreenH, KScreenW, 44);

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    

}

- (void)keyboardWillChange:(NSNotification *)notic{
    
    double time = [notic.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
    
    CGRect frame = [notic.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
    
    [UIView animateWithDuration:time animations:^{
        [UIView setAnimationCurve: 7] ;
        
        if (self.isOut) {
            
            CGRect temp = CGRectMake(self.sendView.frame.origin.x, frame.origin.y - 44, KScreenW, 44);
            self.sendView.frame = temp;

        } else {
            
            CGRect temp = CGRectMake(self.sendView.frame.origin.x, frame.origin.y, KScreenW, 44);
            self.sendView.frame = temp;

        }



    } completion:^(BOOL finished) {


    }];
    
    
}


#pragma mark - tableviewDelegate

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 30;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return  5;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell *tableCell = nil;
    
    if (indexPath.row == 0) {
        
        tableCell = [tableView dequeueReusableCellWithIdentifier:[FriendDynamiCell identifierStr]];
        FriendDynamiCell *dyn = (FriendDynamiCell *)tableCell;
        dyn.delegate = self;
        
    } else if (indexPath.row == 4){
        
        tableCell = [tableView dequeueReusableCellWithIdentifier:[LookMoreCommentCell identifierStr]];

    }else{
        
        tableCell = [tableView dequeueReusableCellWithIdentifier:[FriendCommentCell identifierStr]];

        
        
    }
    
    
    return tableCell;
   
    
}


- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 0.00001;
    
}


- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    
    return 8;
}


- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    
    return [[UIView alloc]init];
}


- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    
    
    return [[UIView alloc]init];
}




- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    self.isOut = NO;
    [self.view endEditing:YES];
}




- (void)commentBtnDidClick{
    
    self.isOut = YES;
        
    [self.sendTextField becomeFirstResponder];
        

    
    
}


- (void)dealloc{
    
    [[NSNotificationCenter defaultCenter]removeObserver:self];
    
}


/*
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
